package com.usian.controller;


import com.usian.pojo.Product;
import com.usian.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Product> products=productService.productfindAll();
        model.addAttribute("product",products);
        return "product";
    }

    @RequestMapping("productAdd")
    public String productAdd(Integer id){
        productService.productAdd(id);
        return "redirect:/product/findAll";
    }

    @RequestMapping("productUp")
    public String productUp(Integer id,Model model){
        Product product=productService.productUp(id);
        model.addAttribute("product",product);
        return "productShiBai";
    }

    @RequestMapping("product")
    public String product(Product product){
        productService.product(product);
        return "redirect:/product/findAll";
    }

    @RequestMapping("productShang")
    public String productShang(Model model){
        List<Product> products=productService.productShang();
        model.addAttribute("product",products);
        return "productShangJia";
    }


    @RequestMapping("products")
    public String products(Integer id){
        productService.products(id);
        return "redirect:/product/productShang";
    }
}
